﻿using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yichat.MicroService.Interface;
using Yichat.MicroService.Model;
using Microsoft.Extensions.Configuration;

namespace Yichat.MicroService.Service
{
    public class ConfigOptionService : IConfigOptionService
    {
        private readonly string _connectionString;
        public ConfigOptionService(IConfiguration configuration)
        {
            _connectionString = configuration.GetConnectionString("Configuration");
        }

        public async Task<IEnumerable<Model.ConfigOption>> GetConfigOptionsAsync()
        {
            using (var connection = new System.Data.SQLite.SQLiteConnection(_connectionString))
            {
                var sql = $"select * from T_Global_ConfigOptions";
                var configs = await connection.QueryAsync<Model.ConfigOption>(sql);
                return configs;
            }
        }
    }
}
